package util


import java.security.MessageDigest

/**
 * zhu.tan@gmail.com
 * 19-Aug-2009
  */

object Md5Sum {
   /*  md5 hash for a array of Byte.  */
  def md5SumString(bytes: Array[Byte]): String = {
    val md5 = MessageDigest.getInstance("MD5")
    md5.reset()
    md5.update(bytes)
    md5.digest().map(0xFF & _).map {"%02x".format(_)}.foldLeft("") {_ + _} // mkString("") === foldLeft(""){_ + _}
  }

  def md5SumString(input: String): String = md5SumString(input.getBytes)
}
